package com.zlzxm.shoesmarket.viewmodel;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.zlzxm.shoesmarket.TestConstant;
import com.zlzxm.shoesmarket.util.RxAndroidHelp;
import com.zlzxm.shoesmarket.view.adapter.entity.EntityMarket;
import com.zlzxm.shoesmarket.view.adapter.entity.EntityTransferGood;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;

/**
 * CREATE BY zlzxm ON 4/13/21
 */
public class VMRequestGoods extends ViewModel {



    public MutableLiveData<List<EntityTransferGood>> liveTransferGood = new MutableLiveData<>();


    public MutableLiveData<List<EntityTransferGood>> getLiveTransferGood() {

        return liveTransferGood;
    }


    public void requestTransferGood(){

        Observable.timer(2, TimeUnit.SECONDS)
                .compose(RxAndroidHelp.turn())
                .subscribe(new Observer<Long>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull Long aLong) {

                    }

                    @Override
                    public void onError(@NonNull Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                        liveTransferGood.setValue(createTestGoods());
                    }
                });



    }


    //<editor-fold defaultState="collapsed" desc="测试">



    private List<EntityTransferGood> createTestGoods(){

        List<EntityTransferGood> list = new ArrayList<>();

        for (int i = 0; i < 10; i++) {

            EntityTransferGood entityTransferGood =  new EntityTransferGood();
            entityTransferGood.setFaceUrl(TestConstant.PIC_NINE);
            entityTransferGood.setNum("货号：33242");
            entityTransferGood.setName("说的说的");
            entityTransferGood.setPeopleNum("求货人数：45");

            List<String> tag = new ArrayList<>();

            tag.add("尺码1");
            tag.add("尺码2444");
            tag.add("尺码3");
            if(i == 0){

                tag.add("尺码4");
                tag.add("尺码5");
                tag.add("尺码161");
                tag.add("尺码162");
                tag.add("尺码163");
                tag.add("尺码16");
                tag.add("尺码16");
                tag.add("尺码163");
                tag.add("尺码163");
                tag.add("尺码163");
            }

            entityTransferGood.setTag(tag);

            list.add(entityTransferGood);
        }

        return  list;
    }

    // </editor-fold>

}
